package com.loveyukari.service;


import com.aliyun.oss.OSSClient;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import java.io.*;

@Service
public class AliCloudUploadService {


    @Value("${yukari.aliyun.endpoint}")
    private String endpoint;


    private Logger logger = LoggerFactory.getLogger(AliCloudUploadService.class);
    private String accessKeyId = "LTAIxk5GYHmgKEra";
    private String accessKeySecret = "hLZauWHcXbVc3WjRRDYWq6SdPEUUvc";

    private String bucket = "loveyukari";

    public void upload(byte[] bs,String fileName) {
        ByteArrayInputStream input = new ByteArrayInputStream(bs);
        upload(input,fileName);
    }

    public void upload(InputStream input,String fileName) {
        OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
        ossClient.putObject(bucket,fileName,input);
        ossClient.shutdown();
    }





}
